<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMessageReceiverTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('message_receiver', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('message_id')->unsigned()->nullable()->comment('消息ID');
            $table->integer('read_at')->unsigned()->nullable()->comment('阅读时间');
            $table->tinyInteger('is_push')->unsigned()->default(0)->comment('是否已推送 0-未推送 1-已推送');
            $table->integer('receiver_id')->unsigned()->nullable()->comment('接受者ID');

            $table->index('is_push');
            $table->index('receiver_id');
            $table->foreign('message_id')->references('id')->on('message');

            $table->softDeletes();
            $table->timestamps();
        });

        \DB::statement("ALTER TABLE `message_receiver` comment '用户消息接受表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('message_receiver');
    }
}
